<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="代理商名称">
                <a-input allow-clear placeholder="请输入代理商名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="手机号码">
                <a-input allow-clear placeholder="请输入手机号码" v-model="queryParam.mobile"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="提现方式">
                <div class="select">
                  <a-select v-model="queryParam.type">
                    <a-select-option value="-1"> 全部 </a-select-option>
                    <a-select-option value="0"> 微信 </a-select-option>
                    <a-select-option value="1"> 支付宝 </a-select-option>
                    <a-select-option value="2"> 银行卡 </a-select-option>
                  </a-select>
                  <a-button type="primary" @click="getShopList">查询</a-button>
                </div>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false" class="card_style_re">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getShopList">
          <a-radio-button value="-1"> 全部 </a-radio-button>
          <a-radio-button value="0"> 待审核 </a-radio-button>
          <a-radio-button value="1"> 已同意 </a-radio-button>
          <a-radio-button value="2"> 已拒绝 </a-radio-button>
        </a-radio-group>
      </div>
      <a-table
        :rowKey="
          (r, i) => {
            return r.id
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="shopList"
        :scroll="{ x: 'max-content' }"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.avatar" alt="" />
            </div>
            <div class="info">
              <span>{{ record.name }}</span>
              <span>{{ record.mobile }}</span>
            </div>
          </div>
        </div>
        <span slot="type" slot-scope="text">
          {{ text == 0 ? '微信' : text == 1 ? '支付宝' : '银行卡' }}
        </span>
        <span slot="account" slot-scope="scope">
          <a-popover title="提现账号">
            <template slot="content">
              <div>{{ scope.type == 0 ? '微信' : scope.type == 1 ? '支付宝' : '银行卡' }}账号:{{ scope.account }}</div>
              <div>
                {{ scope.type == 0 ? '微信昵称' : scope.type == 1 ? '支付宝昵称' : '姓名' }}:{{ scope.account_name }}
              </div>
              <div v-if="scope.type == 2">银行开户行:{{ scope.bank }}</div>
            </template>
            <div>{{ scope.type == 0 ? '微信' : scope.type == 1 ? '支付宝' : '银行卡' }}账号:{{ scope.account }}</div>
          </a-popover>
        </span>
        <span slot="amount" slot-scope="text"> ￥{{ text || '0.00' }} </span>
        <span slot="service_money" slot-scope="text"> ￥{{ text || '0.00' }} </span>
        <div slot="status" slot-scope="scope">
          <div class="status">
            <span :class="scope.status == 0 ? 'warning' : scope.status == 1 ? 'open' : 'close'"></span>
            <span>{{ scope.status == 0 ? '待审核' : scope.status == 1 ? '已同意' : '已拒绝' }}</span>
          </div>
        </div>
        <span slot="action" slot-scope="scope">
          <a-popconfirm title="确认同意吗？" @confirm="changeStatus(scope, '1')">
            <a-button type="link" size="small" :disabled="scope.status != 0">同意</a-button>
          </a-popconfirm>
          <a-divider type="vertical" style="margin: 0 1px" />
          <a-dropdown>
            <a-button type="link" size="small">更多<a-icon type="down" /></a-button>
            <a-menu slot="overlay">
              <a-menu-item v-if="scope.status == 0">
                <a-popconfirm title="确认拒绝吗？" @confirm="changeStatus(scope, '2')">
                  <a-button type="link" size="small">拒绝</a-button>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确认删除吗？" @confirm="delApply(scope)">
                  <a-button type="link" size="small">删除</a-button>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { withdrawList, changeStatus, delApply } from '@/api/saas/agency'
const columns = [
  {
    title: '代理商信息',
    width: 250,
    scopedSlots: {
      customRender: 'name',
    },
  },
  {
    title: '申请时间',
    dataIndex: 'created_at'
  },
  {
    title: '提现方式',
    dataIndex: 'type',
    scopedSlots: {
      customRender: 'type',
    },
  },
  {
    title: '提现账号',
    scopedSlots: {
      customRender: 'account',
    },
  },
  {
    title: '提现金额',
    dataIndex: 'amount',
    scopedSlots: {
      customRender: 'amount',
    },
    sorter: (a, b) => {
      a.amount - b.amount
    },
  },
  {
    title: '服务费',
    dataIndex: 'service_money',
    scopedSlots: {
      customRender: 'service_money',
    },
    sorter: (a, b) => {
      a.service_money - b.service_money
    },
  },
  {
    title: '状态',
    scopedSlots: {
      customRender: 'status',
    },
  },
  {
    title: '操作',
    width: 160,
    scopedSlots: {
      customRender: 'action',
    },
  },
]

export default {
  data() {
    return {
      // 查询参数
      queryParam: {
        name: '',
        mobile: '',
        type: '-1',
        status: '-1',
        pageNo: 1,
        pageSize: 10,
      },
      // 已选中行的id
      selectedRowKeys: [],
      // 门店列表
      shopList: [],
      columns,
      // 数据总条数
      totalCount: 0,
    }
  },
  methods: {
    // 获取进件列表
    async getShopList() {
      const hide = this.$message.loading('加载中', 0)
      const res = await withdrawList(this.queryParam)
      console.log(res)
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.shopList = res.data.data
      }
      hide()
    },
    // 分页请求
    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getShopList()
    },
    // 同意或拒绝门店申请
    audit(id, statua) {
      let that = this
      let text = statua == 1 ? '通过' : '拒绝'
      this.$confirm({
        title: '是否' + text + '申请?',
        async onOk() {
          that.batchAudit([id], statua)
        },
        onCancel() {},
      })
    },
    // 批量操作门店
    async batchAudit(id, shop_audit) {
      const res = await batchAudit({
        id,
        shop_audit,
      })
      if (res.code == 0) {
        this.getShopList()
      }
    },
    // 点击批量同意或拒绝
    allAudit(statua) {
      if (this.selectedRowKeys.length) {
        let that = this
        this.$confirm({
          title: '是否' + statua == 1 ? '通过' : '拒绝' + '申请?',
          async onOk() {
            that.batchAudit(that.selectedRowKeys, statua)
          },
          onCancel() {},
        })
      }
    },
    // 修改申请同意 拒绝状态
    async changeStatus(scope, status) {
      const res = await changeStatus({ id: scope.id, status })
      if (res.code == 0) {
        this.$message.success('操作成功')
        this.getShopList()
      }
    },
    // 删除申请
    async delApply(scope) {
      const res = await delApply({ id: scope.id })
      if (res.code == 0) {
        this.$message.success('删除成功')
        this.getShopList()
      }
    },
  },
  created() {
    this.getShopList()
  },
}
</script>

<style lang="less" scoped>
.searchBox {
  padding: 10px 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-right: 20px;
  }
  .select {
    margin-top: 11px;
    display: flex;
    align-items: center;
    margin-right: 15px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.status {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
  }
  .close {
    background-color: #ff4400;
  }
  .open {
    background-color: #65c817;
  }
  .warning {
    background-color: #eeb041;
  }
}
</style>